package com.zhengtoon.mctoon.conv.controller;

import com.bjtoon.framework.entity.ResponseResult;
import com.qitoon.framework.core.exception.BusinessException;
import com.zhengtoon.mctoon.conv.dto.HandleListQueryDto;
import com.zhengtoon.mctoon.conv.dto.mybatis.Page;
import com.zhengtoon.mctoon.conv.exception.ConvPhotoExceptionCode;
import com.zhengtoon.mctoon.conv.service.ConvHandleRecordService;
import com.zhengtoon.mctoon.conv.utils.AppConstant;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 处理历史记录
 */
@RestController
@RequestMapping("/convphotoManage")
@Api(value = "convphotohandle record服务", description = "convphotohandle record服务")
public class ConvHandleRecordController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(ConvHandleRecordController.class);

    @Autowired
    private ConvHandleRecordService convHandleRecordService;


    /**
     * 查看处理历史   144637
     *
     * @param handleListQueryDto
     * @return ResponseResult
     */
    @ApiOperation(value = "查看处理历史 ", httpMethod = "POST", notes = "查看处理历史")
    @RequestMapping(value = "/queryHandleHistoryById", method = RequestMethod.POST)
    private ResponseResult queryHandleHistoryById(
            @ApiParam(required = true, name = "handleListQueryDto", value = "handleListQueryDto") @RequestBody @Valid HandleListQueryDto handleListQueryDto) {
        try {
            // 1.参数校验
            if (handleListQueryDto.getPageNum() == null
                    || handleListQueryDto.getPageSize() == null) {
                return new ResponseResult<>(ConvPhotoExceptionCode.PARAM_IS_NULL);
            }

            Page page = new Page(handleListQueryDto.getPageNum(), handleListQueryDto.getPageSize());


            page.setParam(handleListQueryDto);

            // 2. 调用service接口
            Page pageResult = convHandleRecordService.queryHandleHistoryById(handleListQueryDto.getId(), page);

            // 3. 返回数据
            return ResponseResult.success(pageResult);
        } catch (BusinessException e1) {
            return new ResponseResult<>(AppConstant.FAIL_CODE, e1.getMessage());
        } catch (Exception e) {
            log.error("queryHandleHistoryById()方法error", e);
            return ResponseResult.fail("", "queryHandleHistoryById()方法error");
        }
    }

}